//
//  MainTabBar.swift
//  WBPoject
//
//  Created by WorkSpace on 15/10/18.
//  Copyright © 2015年 商刻. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let btnCount = 5
        let btnW = self.bounds.size.width / CGFloat(btnCount)
        let btnH = self.bounds.size.height
        let frame = CGRectMake(0, 0, btnW, btnH)
        
        var index = 0
        for v in subviews as [UIView]{
            
            if v is UIControl && !(v is UIButton) {
            
                v.frame = CGRectOffset(frame, CGFloat(index) * btnW, 0)
                
                index++
                
                if index == 2 {
                    index++
                }
            }
        }
        
        composedButton.frame = frame
        composedButton.center = CGPointMake(self.bounds.width / 2.0, self.bounds.height / 2.0)
        
    }

    lazy var composedButton : UIButton = {
    
        let tempButton = UIButton()
        
        tempButton.setImage(UIImage(named: "tabbar_compose_icon_add"), forState:UIControlState.Normal)
        tempButton.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        tempButton.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        tempButton.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(tempButton)
        
        return tempButton
    
    }()

}
